﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class projects : System.Web.UI.Page
    {
        protected DataSet ds;
        protected Security security;

        protected void Page_Load(object sender, EventArgs e)
        {
	        Bug_Util.do_not_cache(Response);
        	
	        security = new Security();
	        security.check_security( HttpContext.Current, Security.MUST_BE_ADMIN);

            titl.Text = Bug_Util.get_setting("AppTitle", "BugTracker.NET") + " - "
		        + "projects";

	        ds = DbUtil.get_dataset(
		        @"select
		        pj_id [id],
		        '<a href=edit_project.aspx?&id=' + convert(varchar,pj_id) + '>edit</a>' [$no_sort_edit],
		        '<a href=edit_user_permissions2.aspx?projects=y&id=' + convert(varchar,pj_id) + '>permissions</a>' [$no_sort_per user<br>permissions],
		        '<a href=delete_project.aspx?id=' + convert(varchar,pj_id) + '>delete</a>' [$no_sort_delete],
		        pj_name [project],
		        case when pj_active = 1 then 'Y' else 'N' end [active],
		        us_username [default user],
		        case when isnull(pj_auto_assign_default_user,0) = 1 then 'Y' else 'N' end [auto assign<br>default user],
		        case when isnull(pj_auto_subscribe_default_user,0) = 1 then 'Y' else 'N' end [auto subscribe<br>default user],
		        case when isnull(pj_enable_pop3,0) = 1 then 'Y' else 'N' end [receive items<br>via pop3],
		        pj_pop3_username [pop3 username],
		        pj_pop3_email_from [from email addressl],
		        case when pj_default = 1 then 'Y' else 'N' end [default]
		        from projects
		        left outer join users on us_id = pj_default_user
		        order by pj_name");
        }

        /// <summary>
        /// 
        /// </summary>
        protected void displaylist()
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                SortableHtmlTable.create_from_dataset(
                    Response, ds, "", "", false);

            }
            else
            {
                Response.Write("No projects in the database.");
            }

        }
    }
}
